package org.jeecg.qis.service.impl;

import org.apache.commons.lang.StringUtils;
import org.jeecg.common.api.CommonAPI;
import org.jeecg.common.api.vo.Result;
import org.jeecg.qis.entity.MesProcDataCfg;
import org.jeecg.qis.mapper.MesProcDataCfgMapper;
import org.jeecg.qis.service.IMesProcDataCfgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.Date;

/**
 * @Description: 设备检验参数配置
 * @Author: LiCY
 * @Date:   2023-06-19
 * @Version: V1.0
 */
@Service
public class MesProcDataCfgServiceImpl extends ServiceImpl<MesProcDataCfgMapper, MesProcDataCfg> implements IMesProcDataCfgService {

    @Autowired
    private CommonAPI commonAPI;
    @Override
    public  void saveProcDataCfg(MesProcDataCfg item) {
        synchronized (this){
            String recID = commonAPI.getRecID("mes_proc_data_cfg", "REC_ID", item.getLine(), item.getOp(), item.getPartno());
            item.setRecId(recID);
            super.save(item);
        }
    }

    @Override
    public Result<String> insertCfg(MesProcDataCfg mesProcDataCfg) {
        String prefix = commonAPI.getPrefix(mesProcDataCfg.getLine(), mesProcDataCfg.getOp(), mesProcDataCfg.getPartno());
        String serialNumber = commonAPI.getProcSerialNumber(mesProcDataCfg.getAddress());
        mesProcDataCfg.setRecId(prefix+serialNumber);
        mesProcDataCfg.setCtime(new Date());
        boolean save = this.save(mesProcDataCfg);
        if (save){
            return Result.OK("新增成功");
        }else {
            return Result.OK("新增失败!");
        }
    }

}
